package com.onlyxiahui.extend.query.hibernate.util;

import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * Description <br>
 * Date 2020-04-09 17:43:58<br>
 * 
 * @author XiaHui [onlovexiahui@qq.com]<br>
 * @since 1.0.0
 */

public class EntityUtil {

	public static String getTableName(Class<?> entityClass) {
		String name = null;
		if (null != entityClass) {
			String entityName = entityClass.getSimpleName();
			Table t = entityClass.getAnnotation(Table.class);
			if (null != t) {
				name = t.name();
			}
			if (null == name || name.isEmpty()) {
				Entity a = entityClass.getAnnotation(Entity.class);
				if (null != a) {
					name = a.name();
				}
			}
			if (null == name || name.isEmpty()) {
				name = entityName;
			}
		}
		return name;
	}
}
